<?php

namespace app\admin\controller\auth;

use app\common\controller\BaseAdminController;
use app\common\model\AuthGroup;

class Group extends BaseAdminController
{
    protected $editField = [
        'id',
        'pid',
        'name',
        'rules',
        'status',
    ];
    public function initialize()
    {
        parent::initialize();
        $this->model = new AuthGroup();
        $allList = $this->model->order('pid asc,id asc')
            ->select()->toArray();
        $allList = array_merge([
            [
                'id' => 0,
                'name' => '顶级分组',
                'pid' => 0,
                'status' => 1,
                'rules' => '',
                'children' => [],
            ]
        ], $allList);
        foreach ($allList as &$v){
            $v['label'] = __($v['name']);
            $v['value'] = $v['id'];
        }
        unset($v);
        $allList = list_to_tree($allList, 'id', 'pid', 'children', 0);
        $this->assignconfig('allList', $allList);
        $allMenu = $this->auth->getRule();
        $this->assignconfig('allMenu', $allMenu);
    }
}